import Buff from '@/Buff';
import BuffUtil from '@/BuffUtil';
import MathUtil from '@/MathUtil';
import SelectUtil from '@/SelectUtil';
import BuffCommon from 'code/Core/Common/BuffCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 龙息术
 **/
export default class FS_DragonBreath extends AbilityBase {
    static instance: FS_DragonBreath;
    buffType: AppBuffType = {
        id: 'buff_FS_DragonBreath',
        art: this.art,
        name: this.abilityName,
        ubertip: '持续onTakeDamage，并且命中下降',
        dur: 3,
        interval: 1,
        onInterval: this.onBuffInterval.bind(this),
        targetAttach: 'chest',
        targetArt: 'Environment\\LargeBuildingFire\\LargeBuildingFire0.mdl',
        attribute: {
            命中: -2,
        },
    };
    constructor(id: string) {
        super(id);
        FS_DragonBreath.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {
        BuffUtil.registerBuffType(this.buffType);
    }
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let angle = MathUtil.angleBetweenCoords(GetUnitX(source), GetUnitY(source), tarX, tarY);
        let es = SelectUtil.getEnemyUnitsInLine(source, GetUnitX(source), GetUnitY(source), 700, angle, 375);
        let lv = this.getAbilityLevel(source);
        let dmg = 20 * lv + UnitCommon.取法强(source) * (0.5 + 0.5 * lv);
        for (let e of es) {
            DamageSystemInstance.applyFireDamage(e, source, dmg, this.id);
            // BuffUtil.addBuff(e, this.buffType.id, source);
            BuffCommon.addBuff({ target: e, caster: source, buffTypeId: this.buffType.id, ablityId: this.id });
        }
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onBuffInterval(buff: Buff) {
        let lv = this.getAbilityLevel(buff.getCaster());
        let dmg = 10 * lv + UnitCommon.取法强(buff.getCaster()) * (0.25 + 0.25 * lv);
        DamageSystemInstance.applyFireDamage(buff.getParent(), buff.getCaster(), dmg, this.id, true);
    }
}
